/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hxg.portmgr.core.device.dslam;

import hxg.portmgr.core.device.intf.AbstractIntf;
import hxg.portmgr.core.oper.snmp.param.AdslParam;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import javax.xml.bind.annotation.*;

/**
 *
 * @author hxg
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {})
@XmlRootElement(name = "LineProfile")
public class LineProfile implements AbstractIntf {

    //@XmlElement
    String index;
    //@XmlElement
    String name;
    String chsname;
    /**
     * Configured allocation ratio of excess transmit bandwidth between fast and
     * interleaved channels. Only applies when two channel mode and RADSL are
     * supported. Distribute bandwidth on each channel in excess of the
     * corresponding ChanConfMinTxRate so that: adslAtucConfRateChanRatio =
     * [Fast / (Fast + Interleaved)] * 100 In other words this value is the fast
     * channel percentage.
     */
    int rateMode = 0;
    //@XmlJavaTypeAdapter(EnumMapAdapter.class)
    EnumMap<AdslParam, Integer> valueMp = new EnumMap<>(AdslParam.class);

    @Override
    public String getIndex() {
        return index;
    }

    public Map<AdslParam, Integer> getValueMap() {
        return Collections.unmodifiableMap(valueMp);
    }

    public int getValue(AdslParam param) {
        if (valueMp.containsKey(param)) {
            return valueMp.get(param);
        } else {
            return -1;
        }
    }
    
    public void setValue(AdslParam param,int value){
        valueMp.put(param, value);
    }

    public String getChsname() {
        if (chsname == null || chsname.isEmpty()) {
            chsname = name;
        }
        return chsname;
    }

    public void setChsname(String chsname) {
        this.chsname = chsname;
    }

    public void addProfileValueMap(Map<AdslParam, Integer> mp) {
        valueMp.clear();
        valueMp.putAll(mp);
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     *
     * @return 0交织模式，100快速模式，中间值表示混合模式
     */
    public int getRateModeIntValue() {
        return rateMode;
    }

    public void setRateMode(int mode) {
        this.rateMode = mode;
    }

    public RateMode getRateMode() {
        switch (rateMode) {
            case 0:
                return RateMode.InterLeaved;
            case 100:
                return RateMode.Fast;
            default:
                return RateMode.FastAndInterLeaved;
        }
    }
    //RateMode rateMode;

    public enum RateMode {

        Fast {
            @Override
            public String toString() {
                return "快速";
            }
        }, InterLeaved {
            @Override
            public String toString() {
                return "交织";
            }
        }, FastAndInterLeaved {
            @Override
            public String toString() {
                return "混合";
            }
        };
    }

    @Override
    public String toString() {
        return getChsname();
    }

    public int getUp() {
        return (getValue(AdslParam.FastUp) * rateMode + getValue(AdslParam.InterLeavedUp) * (100 - rateMode)) / 100;
    }

    public int getDown() {
        return (getValue(AdslParam.FastDown) * rateMode + getValue(AdslParam.InterLeavedDown) * (100 - rateMode)) / 100;
    }

}
